package com.lagou.assignment;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.File;
import java.io.IOException;

/**
 * 程序启动入库
 */
public class DataDriver {


    public static void main(String[] args) throws IOException, IllegalArgumentException, ClassNotFoundException, InterruptedException {

        Configuration entries = new Configuration();
        Job job = Job.getInstance(entries, "DataDriver");
        job.setJarByClass(DataDriver.class);
        job.setMapperClass(DataMapper.class);
        job.setReducerClass(DataReducer.class);

        job.setMapOutputKeyClass(DataBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(DataBean.class);
        job.setOutputValueClass(NullWritable.class);
        // sort排序必须是一个
        job.setNumReduceTasks(1);

        FileInputFormat.addInputPath(job,new Path("data/input"));
        FileOutputFormat.setOutputPath(job, new Path("data/output"));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);

    }
}
